import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { FileInfo } from './types';

/**
 * 上传文件
 *
 * @param file
 */
// export function uploadFileApi(file: File): AxiosPromise<FileInfo> {
//   const formData = new FormData();
//   formData.append('file', file);
//   return request({
//     url: '/files',
//     method: 'post',
//     data: formData,
//     headers: {
//       'Content-Type': 'multipart/form-data',
//     },
//   });
// }

/**
 * 删除文件
 *
 * @param filePath 文件名
 */
export function deleteFileApi(filePath?: string) {
  return request({
    url: '/files',
    method: 'delete',
    params: { filePath: filePath },
  });
}

/**
 * 上传文件
 *
 * @param file
 */
export function uploadFileApi(file: File): AxiosPromise<FileInfo> {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/file/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

/**
 * 删除文件
 *
 * @param fileId 文件id
 */
// export function downloadFileApi(fileId: string | number) {
//   return request({
//     url: '/file/download',
//     method: 'delete',
//     params: { fileId: fileId },
//   });
// }

/**
 * 文件预览
 *
 * @param fileId 文件id
 */
export function previewFileApi(fileId: string | number) {
  return request({
    url: '/file/preview?fileId=' + fileId,
    method: 'get',
  });
}